package org.example;

class Solution {
    public int pivotIndex(int[] nums) {
        int sum = 0;
        for (int num : nums) {
            sum += num;
        }
        int left = 0;
        int i = 0;
        while (i < nums.length && left != sum - left - nums[i]) {
            left += nums[i++];
        }
        if (i < nums.length && left == sum - left - nums[i]) {
            return i;
        }
        return -1;
    }
}

public class Main {
    public static void main(String[] args) {
        System.out.println(new Solution().pivotIndex(new int[]{1, 7, 3, 6, 5, 6}));
    }
}